<?php
/**
 * Created by PhpStorm.
 * User: jin
 * Date: 2015/8/26
 * Time: 15:19
 */

namespace Home\Model;
use Think\Model;

class HosDocModel extends Model
{
    static protected $tName = 'hospital_hospital_doctor';
    /**
     * 插入医院和医生关联表
     * @param int $hosId
     * @param array $docId
     * @return int
     */
    static public function addHosDoc($hosId,$docId)
    {
        $data = array();
        foreach($docId as $docIdKey => $docIdValue)
        {
            $data[] = array(
                'hos_id'=>$hosId,
                'doc_id'=>$docIdValue
            );
        }
        return M()->table(self::$tName)->addAll($data);
    }

    /**
     * 根据hosId删除关联关系
     * @param $hosId
     * @return bool|mixed
     */
    static public function delHosDocForHosId($hosId)
    {
        $where = array();
        //根据传入变量类型确认where条件
        if(is_array($hosId))
        {
            $where = array('hos_id'=>array('in',$hosId));
        }
        else if(is_numeric($hosId))
        {
            $where = array('hos_id'=>$hosId);
        }
        //删除关联关系
        if(count($where))
        {
            return M()->table(self::$tName)->where($where)->delete();
        }
        else
        {
            return false;
        }
    }
    /**
     * 根据docId删除关联关系
     * @param $docId
     * @return bool|mixed
     */
    static public function delHosDocForDocId($docId)
    {
        $where = array();
        //根据传入变量类型确认where条件
        if(is_array($docId))
        {
            $where = array('doc_id'=>array('in',$docId));
        }
        else if(is_numeric($docId))
        {
            $where = array('doc_id'=>$docId);
        }
        //删除关联关系
        if(count($where))
        {
            return M()->table(self::$tName)->where($where)->delete();
        }
        else
        {
            return false;
        }
    }
}